﻿
using System;
using System.Collections.Generic;


namespace LxCFD
{
    public class DistanceUnit
    {
        public List<WallDistance> DistanceInZone = new List<WallDistance>();
        public List<ConnectHeadBase> DistanceInContact = new List<ConnectHeadBase>();
        public DistancePDEUnit CalUnit;
        public void Initialize(List<WallDistance> DistanceInZone, List<ConnectHeadBase> DistanceInContact)
        {
            this.DistanceInZone = DistanceInZone;
            this.DistanceInContact = DistanceInContact;
        }
  
        public void Initialize(bool isForce)
        {
            if (isNeeded(isForce))
            {
                CalUnit = new DistancePDEUnit();
                CalUnit.CalDistance(DistanceInZone, DistanceInContact);
                Finish();
            }
        }
        private bool isNeeded(bool isForce)
        {
            if (DistanceInZone.Count == 0) return false;
            if (!isForce)
            {
                bool isNeededIni = false;
                foreach (var walldis in DistanceInZone)
                {
                    if (!walldis.GetIsInitialized())
                    {
                        isNeededIni = true;
                    }
                }
                if (!isNeededIni) return false;
            }
            return true;
        }
        public void Finish()
        {
            foreach (var g in DistanceInZone)
            {
                g.SetIsInitialized(true);
            }
            CalUnit = null;
            //residualItem = null;
        }

    }
}
//public void AddWallDis(WallDistance wallDis)
//{
//    this.DistanceInZone.Add(wallDis);
//}
//public void AddWallDis(ConnectBase_Head connect)
//{
//    DistanceInContact.Add(connect);
//}
//public List<DistanceUnit> SplitByConnectivity(ConnectivityAnalysisTool connectivityAnalysis)
//{
//    List<DistanceUnit> Units = new List<DistanceUnit>();
//    var pools = connectivityAnalysis.Analysis(DistanceInZone, DistanceInContact);
//    foreach (var p in pools)
//    {
//        DistanceUnit u = new DistanceUnit();
//        foreach (int z in p.zonesIndex)
//        {
//            u.AddWallDis(DistanceInZone[z]);
//        }
//        foreach (int c in p.contactsIndex)
//        {
//            u.AddWallDis(DistanceInContact[c]);
//        }
//        Units.Add(u);
//    }
//    return Units;
//}